﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Controllers;
using QLBH.Models;
using QLBH.Report;
using QLBH.Utilities;

namespace QLBH.Modules
{
    public partial class ucWarehouse : UserControl
    {
        private WarehouseController controller;
        public ucWarehouse()
        {
            InitializeComponent();
            this.dgvWarehouse.AutoGenerateColumns = false;
            controller = new WarehouseController(this);
        }
        public void DisplayData(List<WarehouseModel> model)
        {
            this.dgvWarehouse.DataSource = model;
        }
        private void ucWarehouse_Load(object sender, EventArgs e)
        {
            controller.LoadData();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.Add();
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {            
            controller.Edit();
        }

        public WarehouseModel getCurrentSelectedItem()
        {
            if (dgvWarehouse.SelectedRows.Count > 0)
            {
                return dgvWarehouse.SelectedRows[0].DataBoundItem as WarehouseModel;
            }
            return null;             
        }


        private void btnDelete_Click(object sender, EventArgs e)
        {
            controller.Delete();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            controller.LoadData();
        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void btnPrintf_Click(object sender, EventArgs e)
        {
            frmReport.dt = CollectionHelper.ConvertTo(WSAccess.GetData<List<WarehouseModel>>(MainForm.Instance.Shop_id.ToString() + "/warehouse"));
            frmReport.Type = "ReportWarehouse";
            frmReport fm = new frmReport();
            fm.ShowDialog();
        }
    }
}
